//////////////////////////////////////////////////////////////////////////////////
//	 Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#ifndef _SYS_LOG_TAB_YG_H__
#define _SYS_LOG_TAB_YG_H__

#include "def.h"
#include "logctrl.h"
#include "searchimpl.h"

class CSysLogTab: public wxPanel, public CSearchImpl<CSysLogTab>, public IGUIBind, public IGUISupport, public ITabedPageUI
{
public:
								CSysLogTab(class wxWindow* pParent );
	virtual						~CSysLogTab(void);

	//IGUIBind
	virtual void				OnResponse(const COMMANDRESPONSE& resp);

	//IGUISupport
	virtual bool				CanSave()	{ return  !m_storage.empty(); }
	virtual wxString			Save();
	virtual bool				CanClear()	{ return  !m_storage.empty(); }
	virtual void				Clear();


	//ISearchProvider
	virtual void 				GetSearchFields(SEARCHFIELD*& sf, size_t& sz);
	virtual cSearchOwnerID		GetID()				{ return cSearchOwnerIDSysLog; }
	virtual void				OnFilterChanged();

	bool						OnDropText(wxCoord x, wxCoord y, const wxString& data) { return false; }
	void						OnDragDropFinished( wxWindowID id, wxDragResult result) {}

	void						OnContextMenu(long id, long col) {} 

	long						GetItemCount(wxWindowID id=wxID_ANY)
	{
		return m_storage.size();
	}

	wxString					GetItemText(long item, long column, wxWindowID id=wxID_ANY);

	int							GetItemColumnImage(long item, long column, wxWindowID id=wxID_ANY);

	virtual int					GetItemImage(long item, wxWindowID id=wxID_ANY);

	static wxString				GenerateFacilName(int iFac);
	static wxString				GeneratePrioName(int iPrio);

	void						OnNewLogMsg(wxCommandEvent& event);

	virtual cTabPageID			GetTabID() { return cTabIDSysLog; }

protected:
	
	void						OnColumn(wxListEvent& ev);
	DECLARE_EVENT_TABLE()

private:
	wxString					FieldToString( int column, const SYSLOGMSG& entry);
	void						ProcessData();
	void						DoFilter();
	void						DoSort();

private:
	class CSearchPanel*			m_pSearch;
	bool						m_bSortAsc;
	class wxListCtrl*			m_pList;
	SYSLOGMSGSTORE				m_storage;
	SYSLOGMSGSTORE				m_beforeFilter;
	SYSLOGMSGSTORE				m_newEntries;
	unsigned int				m_nSortCol;
	class wxImageList*			m_pImageList;
};

#endif //_SYS_LOG_TAB_YG_H__